﻿using Unity.Burst;
using Unity.Entities;
using Unity.Transforms;
using UnityEngine;


//public partial class RotationSystem : SystemBase
//{
//    protected override void OnUpdate()
//    {

//    }
//}
[DisableAutoCreation]
public partial struct RotationSystem : ISystem
{
    //只会在 存在一个实体 拥有 RotComp组件的才会创建该系统
    //public void OnCreate(ref SystemState state)
    //{
    //    state.RequireForUpdate<RotComp>();
    //}
    //[BurstCompile]
    //public void OnCreate(ref SystemState state)
    //{
    //    state.RequireForUpdate<MoveAspect>();
    //}

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        //state.Enabled = false;
        //return;

        ///*
        //foreach (var (localTransform , rotComp) in SystemAPI.Query<RefRW<LocalTransform>,RefRW<RotComp>>())
        //{
        //    //localTransform.ValueRW = localTransform.ValueRW.RotateY(rotComp.ValueRO.angle * SystemAPI.Time.DeltaTime);
        //    localTransform.ValueRW.Rotation = Quaternion.Euler(0, 0, rotComp.ValueRO.angle);
        //}
        //foreach (MoveAspect moveAspect in SystemAPI.Query<MoveAspect>())
        //{
        //    moveAspect.transform.ValueRW.Rotation = Quaternion.Euler(0, 0, moveAspect.rotComp.ValueRO.angle);
        //}

        //*/
        //RotationSystemJob rotationSystemJob = new RotationSystemJob { deltaTime = SystemAPI.Time.DeltaTime };
        //rotationSystemJob.ScheduleParallel();
    }

    //[BurstCompile]
    //[WithAll(typeof(PlayerTag))]
    //partial struct RotationSystemJob : IJobEntity
    //{
    //    public float deltaTime;
    //    //写用ref,读用in
    //    public void Execute(ref LocalTransform localTransform, in RotComp rotComp)
    //    {
    //        localTransform = localTransform.RotateY(rotComp.angle * deltaTime);
    //    }
    //}
}


